import * as echarts from '@/plugin/lime-echart/static/echarts.min'
import store from '@/store'
export default {
    data() {
        return{
            chart1Option:{},
            chart1:{
                position: [],
                params: [],
                load:false
            },
            chart2Option:{},
            chart2:{
                position: [],
                params: [],
                load:false
            },
            chart3Option:{},
            chart3:{
                position: [],
                params: [],
                load:false
            },
            chart4Option:{},
            chart4:{
                position: [],
                params: [],
                load:false
            },
        }
    },
    methods: {

        getChart1Option(data){
            if(data.length == 0){
                return;
            }
            let axisData = data.map(item=>item.batchNo);
            let seriesData = data.map(item=>this.getNumber(item.rewardAmount));
            let option={
                color: ['#165DFF', '#F7BA1E', '#14C9C9'],
                xAxis: {
                    type: 'category',
                    data: axisData,
                    axisTick:{
                        show:false
                    },
                    axisLine:{
                        show:false
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLabel:{
                        show:false
                    },
                    splitLine:{
                        show:false
                    }
                },
                grid:{
                    left: '10',
                    right: '10',
                    bottom: '0',
                    top: '10',
                    containLabel: true
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    position: (point, params, dom, rect, size) => {
                        // 假设自定义的tooltips尺寸
                        const box = [140, 70]
                        // 偏移
                        const offsetX = point[0] < size.viewSize[0] / 2 ? 20 : -box[0] - 20;
                        const offsetY = point[1] < size.viewSize[1] / 2 ? 20 : -box[1] - 20;
                        const x = point[0] + offsetX;
                        const y = point[1] + offsetY;
                        this.chart1.position = [x, y]
                        this.chart1.params = [params[0]]
                    },
                    formatter: (params, ticket, callback) => {
                    }
                },
                series: [
                    {
                        // name:"总利润",
                        label: {
                            show: true,
                            position: 'top'
                        },
                        barMaxWidth: 40,
                        data: seriesData,
                        type: 'bar'
                    }
                ]
            };
            if(axisData.length>12){
                option.dataZoom = [
                    {
                        show: false,
                        start: 0,
                        end: 50
                    },
                    {
                        type: 'inside',
                    }
                ]
            }
            this.chart1Option = option;
            if(this.chart1.load){
                this.$refs.chart1.setOption(this.chart1Option);
                this.$refs.chart1.resize()
            }else{
                this.$refs.chart1.init(echarts, chart=> {
                    chart.setOption(this.chart1Option);
                    chart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: 2
                    })
                    chart.resize()
                    this.chart1.load = true;
                });
            }
        },
        getChart2Option(data){
            if(data.length == 0){
                return;
            }
            let axisData = data.map(item=>item.batchNo);
            let seriesData = data.map(item=>item.rewardAmount);
            let option={
                color: ['#165DFF', '#F7BA1E', '#14C9C9'],
                xAxis: {
                    type: 'category',
                    data: axisData,
                    axisTick:{
                        show:false
                    },
                    axisLine:{
                        show:false
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLabel:{
                        show:false
                    },
                    splitLine:{
                        show:false
                    }
                },
                grid:{
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top: '20',
                    containLabel: true
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    position: (point, params, dom, rect, size) => {
                        // 假设自定义的tooltips尺寸
                        const box = [140, 70]
                        // 偏移
                        const offsetX = point[0] < size.viewSize[0] / 2 ? 20 : -box[0] - 20;
                        const offsetY = point[1] < size.viewSize[1] / 2 ? 20 : -box[1] - 20;
                        const x = point[0] + offsetX;
                        const y = point[1] + offsetY;
                        this.chart2.position = [x, y]
                        this.chart2.params = [params[0]]
                    },
                    formatter: (params, ticket, callback) => {
                    }
                },
                series: [
                    {
                        // name:"总利润",
                        label: {
                            show: true,
                            position: 'top'
                        },
                        barMaxWidth: 40,
                        data: seriesData,
                        type: 'bar'
                    }
                ]
            };
            if(axisData.length>12){
                option.dataZoom = [
                    {
                        show: false,
                        start: 0,
                        end: 50
                    },
                    {
                        type: 'inside',
                    }
                ]
            }
            this.chart2Option = option;
            if(this.chart2.load){
                this.$refs.chart2.setOption(this.chart2Option);
            }else{
                this.$refs.chart2.init(echarts, chart=> {
                    chart.setOption(this.chart2Option);
                    chart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: 2
                    })
                    this.chart2.load = true;
                });
            }
        },
        getChart3Option(data){
            if(data.length == 0){
                return;
            }
            let axisData = data.map(item=>item.batchNo);
            let seriesData = data.map(item=>item.rewardAmount);
            let option={
                color: ['#165DFF', '#F7BA1E', '#14C9C9'],
                xAxis: {
                    type: 'category',
                    data: axisData,
                    axisTick:{
                        show:false
                    },
                    axisLine:{
                        show:false
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLabel:{
                        show:false
                    },
                    splitLine:{
                        show:false
                    }
                },
                grid:{
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top: '20',
                    containLabel: true
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    position: (point, params, dom, rect, size) => {
                        // 假设自定义的tooltips尺寸
                        const box = [140, 70]
                        // 偏移
                        const offsetX = point[0] < size.viewSize[0] / 2 ? 20 : -box[0] - 20;
                        const offsetY = point[1] < size.viewSize[1] / 2 ? 20 : -box[1] - 20;
                        const x = point[0] + offsetX;
                        const y = point[1] + offsetY;
                        this.chart3.position = [x, y]
                        this.chart3.params = [params[0]]
                    },
                    formatter: (params, ticket, callback) => {
                    }
                },
                series: [
                    {
                        // name:"总利润",
                        label: {
                            show: true,
                            position: 'top'
                        },
                        barMaxWidth: 40,
                        data: seriesData,
                        type: 'bar'
                    }
                ]
            };
            if(axisData.length>12){
                option.dataZoom = [
                    {
                        show: false,
                        start: 0,
                        end: 50
                    },
                    {
                        type: 'inside',
                    }
                ]
            }
            this.chart3Option = option;
            if(this.chart3.load){
                this.$refs.chart3.setOption(this.chart3Option);
            }else{
                this.$refs.chart3.init(echarts, chart=> {
                    chart.setOption(this.chart3Option);
                    chart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: 2
                    })
                    this.chart3.load = true;
                });
            }
        },
        getChart4Option(data){
            if(data.length == 0){
                return;
            }
            let axisData = data.map(item=>item.batchNo);
            let seriesData = data.map(item=>item.rewardAmount);
            let option={
                color: ['#165DFF', '#F7BA1E', '#14C9C9'],
                xAxis: {
                    type: 'category',
                    data: axisData,
                    axisTick:{
                        show:false
                    },
                    axisLine:{
                        show:false
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLabel:{
                        show:false
                    },
                    splitLine:{
                        show:false
                    }
                },
                grid:{
                    left: '10',
                    right: '10',
                    bottom: '10',
                    top: '20',
                    containLabel: true
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    position: (point, params, dom, rect, size) => {
                        // 假设自定义的tooltips尺寸
                        const box = [140, 70]
                        // 偏移
                        const offsetX = point[0] < size.viewSize[0] / 2 ? 20 : -box[0] - 20;
                        const offsetY = point[1] < size.viewSize[1] / 2 ? 20 : -box[1] - 20;
                        const x = point[0] + offsetX;
                        const y = point[1] + offsetY;
                        this.chart4.position = [x, y]
                        this.chart4.params = [params[0]]
                    },
                    formatter: (params, ticket, callback) => {
                    }
                },
                series: [
                    {
                        // name:"总利润",
                        label: {
                            show: true,
                            position: 'top'
                        },
                        barMaxWidth: 40,
                        data: seriesData,
                        type: 'bar'
                    }
                ]
            };
            if(axisData.length>12){
                option.dataZoom = [
                    {
                        show: false,
                        start: 0,
                        end: 50
                    },
                    {
                        type: 'inside',
                    }
                ]
            }
            this.chart4Option = option;
            if(this.chart4.load){
                this.$refs.chart4.setOption(this.chart4Option);
            }else{
                console.log(this.$refs.chart4)
                this.$refs.chart4.init(echarts, chart=> {
                    chart.setOption(this.chart4Option);
                    chart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: 2
                    })
                    this.chart4.load = true;
                });
            }
        },
        toPage(url,options){
            if(!this.isLogin){
                uni.showModal({
                    title: '温馨提示',
                    content: '此时此刻需要您登录喔~',
                    // showCancel: false,
                    confirmText: "去登录",
                    cancelText: "再逛会",
                    success: res => {
                        if (res.confirm) {
                            uni.navigateTo({
                                url: "/page_work/login/index"
                            })
                        }
                    }
                })
            }else{
                this.$navTo(url,options)
            }
        },
        goDividends(){
            this.toPage('page_work/user/dividends',{
                shareRate:this.shareRate,
                shareAmount:this.shareAmount,
            })
        },
        goOrder(){
            this.toPage('page_work/user/order')
        },
        goBpw(){
            this.toPage('page_work/user/exchange')
        },
        goInvite(){
            this.toPage('page_work/user/invite')
        },
        goReward(){
            this.toPage('page_work/user/reward')
        },
        goEquity(){
            this.toPage('page_work/user/share')
        },
        goKlines(){
            this.toPage('page_work/klines/klines')
        },
        goSetting(){
            this.toPage('page_work/user/setting')
        },
        //我的股权统计信息
        myStat(){
            this.$request.get('wx/share/myStat',{},{load:false}).then(res=>{
                // console.log(res)
                if(res.data){
                    const data = res.data;
                    this.stat.usedShareAmount=data.usedShareAmount || 0;//已兑换份额
                    this.stat.shareRate=data.shareRate|| 0;// 股权份额比例，需要转换成百分制
                    this.stat.shareAmount=data.shareAmount|| 0;//我的总份额
                    this.stat.availableShareAmount=data.availableShareAmount|| 0;// 可兑换份额
                    this.stat.lockedShareAmount=data.lockedShareAmount|| 0;// 锁仓份额
                    this.stat.totalOrderAmount=data.totalOrderAmount|| 0;// 已购总金额
                    this.stat.inviteCount=data.inviteCount|| 0;// 邀请人数
                    this.stat.inviteTotalAmount=data.inviteTotalAmount|| 0;// 邀请总金额
                    this.stat.inviteTotalShare=data.inviteTotalShare|| 0;// 邀请总股权
                    // console.log(this.stat)
                    store.commit('SET_USER_STAT', this.stat)
                }
            })
        },
        getMyBoard(){
            this.$request.get('wx/reward/myBoard',{},{load:false}).then(res=>{
                if(res.data && res.data.items){
                    const data = res.data.items;
                    this.board.totalRewardPoolAmount=data.totalRewardPoolAmount || 0;
                    this.board.sumRewardPoolAmount=data.sumRewardPoolAmount|| 0;
                    this.board.myOrderRewardAmount=data.myOrderRewardAmount|| 0;
                    this.board.myInviteRewardAmount=data.myInviteRewardAmount|| 0;
                }
            })
        }
    }
};